﻿// MainWindows.xaml.cs
// 
// Copyright (C) 2008-2010 Scott Wegner
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using PwdhashSharp.Library;
using System.Security;
using System.Runtime.InteropServices;

[assembly: CLSCompliant(true)]
namespace PwdhashSharp.Wpf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private const int AddressTextBoxWidth = 500;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void generateButton_Click(object sender, RoutedEventArgs e)
        {
            GeneratePasswordView();
        }

        private void GeneratePasswordView()
        {
            string hashedPass = GeneratePassword(siteAddressTextBox.Text, sitePasswordBox.Password);
            
            generatedPasswordTextBox.Text = hashedPass;
            generatedPasswordTextBox.IsEnabled = true;

            generatedPasswordTextBox.SelectAll();
            generatedPasswordTextBox.Focus();            
        }

        private string GeneratePassword(string domain, string sitePassword)
        {

            PasswordHasher hasher = new PasswordHasher(domain, sitePassword);
            return hasher.CreateHashedPassword();
        }
    }
}
